var ns;
var app = new Vue({
    el: '#app',
    data: {
        MemberQRPath: '',
        IsShow: false, //是否显示基本信息
        IsjifenShow: false, //是否显示积分
        memberPrice: '', //金额
        memberIntegral: '', //积分
        form: {},
        roomid: '', //资源位置ID
        fullname: '', //资源位置
        keySearch: '',
        keyRoomSearch: '',
        selType: 0,
        relationname:'',//业主名称
        convertrule: {} //积分规则
    },
    methods: {
        get_data: function() {
            var that = this;
            //alert(that.MemberQRPath);
            //获取会员卡信息
            if (that.MemberQRPath != '') {
                var options = {};
                options.action = 'getmemberinfobymemberqrpath';
                options.MemberQRPath = that.MemberQRPath;
                ns.post(options, function(succeed, data, err) {
                    if (succeed) {
                        if (data != null) {
                            that.IsShow = true;
                            //alert(JSON.stringify(data));
                            that.form = data;
                            if (data.viewRoomBasics.length > 0) {
                                that.roomid= data.viewRoomBasics[0].id;
                                that.fullname = data.viewRoomBasics[0].fullname;
                                that.relationname = data.viewRoomBasics[0].relationname;
                            }
                            that.get_data1();
                        }
                    }
                });
            } else {
                api.toast({
                    msg: '未扫描到数据',
                    duration: 2000,
                    location: 'bottom'
                });
            }
        },
        //获取积分规则
        get_data1: function() {
            var that = this;
            var potions = {
                action: 'getmallamountpointconvertrulebybusenissid'
            };
            ns.post(potions, function(succeed, data, err) {
                if (succeed) {
                    //alert(JSON.stringify(data));
                    that.convertrule = data;
                    if (that.convertrule != null) {

                        that.IsjifenShow = true;
                        //alert(that.IsShow);
                    }
                }
            });
        },
        do_save: function() {
            var that = this;
            //alert(that.form.memberPrice);
            if (that.memberPrice == "" || that.memberPrice == null || that.memberPrice == 0) {
                api.toast({
                    msg: '请输入金额',
                    duration: 3000,
                    location: 'bottom'
                });
                return;
            }
            var options = {
                action: 'addorderandpoint',
                userid: that.form.UserID, //会员ID
                memberPrice: that.memberPrice, //金额
                IsjifenShow: that.IsjifenShow, //是否增加积分
                memberIntegral: that.memberIntegral, //最终积分
                roomid: that.roomid, //资源位置ID
                fullname: that.fullname //资源位置
            };
            ns.post(options, function(succeed, data, err) {
                if (succeed) {

                    api.toast({
                        msg: "提交成功",
                        duration: 2000,
                        location: 'bottom'
                    });
                    api.sendEvent({
                        name: 'saveorder',
                    });

                    api.closeWin();
                }
            });
            // //确认登记操作
            //  if(that.IsjifenShow){
            //     //增加积分
            //  }
            //  else {
            //
            //  }
        },
        do_cancel: function() {
            var that = this;
            //取消登记操作
            api.closeWin();

        },
        onChangePrice: function() {
            var that = this;
            if (that.IsjifenShow) {
                //积分兑换规则：1人民币=2积分
                var price = that.memberPrice;
                // 向上取整
                // var ceil = Math.ceil(5 / 2)
                // 向下取整
                // var floor = Math.floor(5 / 2)
                // 四舍五入
                that.memberIntegral = Math.round(price * that.convertrule.ConvertRate);
            }
        },
        getname:function(name){
           if(name.length>1){
             return name.replace(name.substr(0,1),"*");
           }
           else{
              return "";
           }
        }
    }
});
apiready = function() {
    api.parseTapmode();
    ns = window.Foresight.Util;
    app.MemberQRPath = api.pageParam.MemberQRPath;
    app.get_data();
};
